﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
using SimulationCore.Net.DTO;
using SimulationPresenter.Presentation.Primitives;
using SimulationPresenter.Simulation.Helpers;
using SimulationPresenter.Simulation.Primitive;
using SimulationPresenter.Simulation.Helpers.BaseShapes;

namespace SimulationPresenter.Theater
{
    internal class RidigActorPrimitive : Actor, IActorPropertiesProvider, ISimulatable
    {
        protected IRidig state;
        
        public ISimulationPrimitive State
        {
            get
            {
                return state;
            }
        }

        /// <summary>
        /// Gets position in World space of a box
        /// </summary>
        public Vector3 Position
        {
            get
            {
                //Get position from World Transformation Matrix
                if (null == state)
                {
                    throw new InvalidOperationException(
                        "Position could not be generated. There is no state defied for actor.");
                }

                var position = new Vector3(0, 0, 0);
                position.TransformCoordinate(state.Transformation);

                return position;
            }
        }

        public string Name
        {
            get
            {
                if (null == state)
                {
                    throw new InvalidOperationException(
                        "Name could not be get. There is no state defied for actor.");
                }

                return state.Name;
            }
        }

        override public string ToString()
        {
            try
            {
                return Name;
            }
            catch (InvalidOperationException)
            {
                return "Unknown";
            }
        }

        public bool Visible
        {
            get;
            set;
        }

        /// <summary>
        /// Updates state of an Actor based on Core Actors' States list
        /// </summary>
        /// <param name="actorsState"></param>
        public void UpdateState(IList<ActorState> actorsState)
        {
            var actorState = state.FindOwnState(actorsState);
            //Use helper to update the state
            state.UpdateSimulationState(actorState);
            //shape.UpdateState(actorState);
        }
    }
}
